package com.vitas.coin.ui.fm

import android.view.View
import com.snap.base.ktx.getAppVer
import com.snap.base.ktx.isOnline
import com.snap.base.ktx.requestLatestVer
import com.snap.base.ktx.setAppVer
import com.snap.base.ktx.setVipDesc
import com.snap.base.util.BaseUtil
import com.snap.base.vm.UserVM
import com.snap.common.main.BaseMVVMFg
import com.snap.util.appVerName
import com.snap.util.toast
import com.snap.view.SettingCellAdapter.setDetail
import com.vitas.coin.R
import com.vitas.coin.databinding.FrgMineBinding
import com.vitas.coin.ui.dialog.CollectListDialog
import com.vitas.coin.util.AdUtil
import com.vitas.coin.vm.MineVM


class MineFrg : BaseMVVMFg<FrgMineBinding, MineVM>() {

    override fun createVM(): MineVM {
        return MineVM()
    }

    override fun doDataBind() {
        binding.viewModel = viewModel
        binding.userVM = UserVM
    }

    override fun getContentViewId(): Int {
        return R.layout.frg_mine
    }

    override fun onViewCreated() {
        if (BaseUtil.isOnline()) {
            BaseUtil.setVipDesc(this, binding.tvDesc)
        } else {
            binding.tvDesc.text = "手机铃声随心听"
        }

        binding.tvVer.text = BaseUtil.getAppVer()
        BaseUtil.setAppVer(this, binding.tvVer)

        AdUtil.adNative(requireActivity(), binding.flAd)

        initEvent()
        viewModel.actionUpdate = {
            showVersion(true)
        }
        viewModel.actionAct = { requireActivity() }
    }
    private suspend fun showVersion(isShowUpdate: Boolean = false) {
        BaseUtil.requestLatestVer(isShowUpdate, requireActivity()).apply {
            if (isShowUpdate) {
                toast("当前已是最新版本")
            }
        }
    }

    private fun initEvent() {
        binding.llCollect.setOnClickListener {
            context?.let {
                CollectListDialog(it) {

                }.showXY(binding.clRoot)
            }
        }
    }



}